<?php
function json_out($code, $data, $return=false) {
	if ($code != 0) {
		$json = array('success'=>false, 'code' => $code, 'message' => $data);
	}
	else {
		$json = array('success'=>true, 'code' => 0, 'result' => $data);
	}

	if ($return === true) {
		return json_encode($json);
	}

	header("Content-Type:application/json; charset=utf-8"); // Unsupport IE
	header("Access-Control-Allow-Origin: *");
	echo json_encode($json);
	exit;
}

function json_raw($code, $data, $return=false) {
	if ($code != 0) {
		$json = array('code' => $code, 'message' => $data);
	}
	else {
		$json = &$data;
	}

	if ($return === true) {
		return json_encode($json);
	}

	header("Content-Type:application/json; charset=utf-8"); // Unsupport IE
	header("Access-Control-Allow-Origin: *");
	echo json_encode($json);
	exit;
}